<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>allocateProjectToWorkers</title>
        <style>
        table{border-collapse:collapse;border-spacing:0;border-left:1px solid #888;border-top:1px solid #888;margin: auto}
        th,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;}
        th{font-weight:bold;}
        body{text-align: center}
    </style>
    {% load static %}
    <script type='text/javascript' src="/static/js/jquery.min.js"></script>
    <script type='text/javascript' src="/static/js/user.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("input[name='submit']").click(function(){
                var projectId = $("input[name='projectId']").val();
                var userId = $(this).parent().parent().find("td:first").next().find("input").val();
                var crf = $("input[name='csrfmiddlewaretoken']").val();
                var status = $(this).next("input").val();
                status = status==1?0:1;
                $.ajax({
                    url:'/doAllocateProject/',
                    data:{projectId:projectId,userId:userId,status:status,csrfmiddlewaretoken:crf},
                    type:'POST',
                    success:function(data){
                        if(data == '1'){
                            alert('分配成功');
                            location.reload();
                        }else{
                            alert('分配失败');
                            location.reload();
                        }
                    }
                });
            });
        });
    </script>
</head>
<body>
<div style="width: 80%;height:40px;background-color: aqua;margin: 0 auto ">
    <div style="float:left;margin-left: 10px;margin-top: 10px"><a href="#" name="projectManager">项目管理&nbsp;&nbsp;</a>|</div>
    <div style="float:left;margin-left: 10px;margin-top: 10px"><a href="#" name="testCaseManager">测试用例管理&nbsp;&nbsp;</a>|</div>
    <div style="float:left;margin-left: 10px;margin-top: 10px"><a href="#" name="bugCheck">bug情况查看&nbsp;&nbsp;</a>|</div>
    <div style="float:right;margin-right:10px;margin-top: 10px"><a href="#" name="logout">退出</a></div>
    <div style="float:right;margin-right:10px;margin-top: 10px">登录人：{{ request.session.showName }}&nbsp;&nbsp;</div>
    <form method="post" name="dataForm">
        {% csrf_token %}
        <input type="hidden" name="dataInput" />
    </form>
</div><p></p>
<table>
    <tr>
        <td width="100px">待分配项目</td>
        <td width="360px">
        {% for project in projects %}
            {{ project.projectName }}
            <input type="hidden" name="projectId" value="{{ project.id }}"/>
        {% endfor %}
        </td>
    </tr>
</table>
<p>
<table>
    <tr>
        <td width="100px">工作人员ID</td>
        <td width="100px">工作人员</td>
        <td width="100px">分配状态</td>
        <td width="100px">操作</td>
    </tr>
    {% for relation in relations %}
        <tr>
            <td>{{ relation.user.id }}</td>
            <td>
                {{ relation.user.showName }}
                <input type="hidden" value="{{ relation.user.id }}" name="userId"/>
            </td>
            <td>
                {% if relation.status == 1 %}
                    <font color="green">已分配</font>
                {% else %}
                    <font color="red"> 未分配</font>
                {% endif %}

            </td>
            <td>
                <input type="button" name="submit" value="{% if relation.status == 1 %}取消{% else %}分配{% endif %}"/>
                <input type="hidden" name="status" value="{{ relation.status }}"/>
            </td>
        </tr>
    {% endfor %}
</table>
{% csrf_token %}
</body>
</html>